﻿CREATE TABLE [dbo].[Teams] (
    [ID]   INT            IDENTITY (1, 1) NOT NULL,
    [Name] NVARCHAR (MAX) NULL,
    CONSTRAINT [PK_dbo.Teams] PRIMARY KEY CLUSTERED ([ID] ASC)
);


GO
CREATE TRIGGER [dbo].[TeamDelete]
 ON [dbo].[Teams]
 INSTEAD OF DELETE
 AS
 BEGIN;
     DELETE FROM AssignmentTeams WHERE TeamID IN (SELECT ID FROM DELETED);
     DELETE FROM DiscussionTeams WHERE TeamID IN (SELECT ID FROM DELETED);
     DELETE FROM DiscussionTeams WHERE AuthorTeamID IN (SELECT ID FROM DELETED);
     DELETE FROM ReviewTeams WHERE AuthorTeamID IN (SELECT ID FROM DELETED);
     DELETE FROM ReviewTeams WHERE ReviewTeamID IN (SELECT ID FROM DELETED);
     DELETE FROM RubricEvaluations WHERE RecipientID IN (SELECT ID FROM DELETED);
     DELETE FROM TeamMembers WHERE TeamID IN (SELECT ID FROM DELETED);
     DELETE FROM Teams WHERE ID IN (SELECT ID FROM DELETED);
 END;